home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / prospero / PRM / src / testprog / timered.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-15  |  2.2 KB  |  106 lines

  1. /*
  2.  * Copyright (c) 1992, 1993 by the University of Southern California
  3.  *
  4.  * For copying and distribution information, please see the files
  5.  * <prm-copyr.h>.
  6.  */
  7.  
  8. #include <prm-copyr.h>
  9.  
  10.  
  11. #include <stdio.h>
  12. #include <sys/time.h>
  13. #include <sys/resource.h>
  14. #include <sys/times.h>
  15.  
  16. #define  MAIN_PROG
  17. #include <comm.h>   /*     This file defines certain constants, and declares
  18.             some global variables used by the message passing
  19.             routines.  */
  20. #include <CMMDlib.h>
  21.  
  22.  
  23. #ifdef HPUX
  24. #   define srandom srand
  25. #   define random rand
  26. #endif
  27.  
  28. #ifndef NUM_ITER 
  29. #  define NUM_ITER 500
  30. #endif
  31.  
  32. #ifndef ASIZE
  33. #  define ASIZE 1
  34. #endif
  35.  
  36. #ifndef RNEIGH
  37. #   define RNEIGH(x,tot)    (x<tot)?x+1:1 /* right neighbor of x in the ring */
  38. #endif
  39.  
  40. #define MAXTIME 12                        /* Maximum computation time in sec.*/
  41. #define INT_SZ sizeof(int)
  42. #define SENDTO_PORT 1                     /* Port_id on destination task */
  43. #define RCVON_PORT  1                     /* Port on which to rcv messages */
  44.  
  45.  
  46. float a[ASIZE];
  47.  
  48. char *progname;
  49.  
  50. main(argc, argv)
  51. int argc;
  52. char **argv;
  53. {
  54.   int ntasks, my_tid, num_iter;
  55.   int time_dcrmt, timeleft, iter_cnt;
  56.   int sendto_task, i, nbytes, rbytes, dum;
  57.   double time, val, red_val;
  58.   char fname[32];
  59.   struct rusage rusage1, rusage2;
  60.   FILE *fd;
  61.   struct timeval tp1, tp2;
  62.   struct timezone tzp;
  63.  
  64.   init_task(argv);    /* Initialization is required for all tasks in every
  65.              application */
  66.  
  67.   nbytes = sizeof(float) * ASIZE;
  68.   pfs_debug=0;
  69.   my_tid = gettid(); 
  70.   if (my_tid == -1) {
  71.     io_printf(" task could not get its tid!", (char *)0);
  72.     exit(1);
  73.   }
  74.   
  75.   num_iter = 100;
  76.   ntasks = numtasks();   /* Total number of tasks in this job */
  77.   
  78.   red_val = (double)1.0;
  79.   
  80.   val = CMMD_reduce_double(red_val, CMMD_combiner_add);
  81.  
  82.   gettimeofday(&tp1, &tzp);  
  83.  
  84.   for (i=1; i<= num_iter; i++) {
  85.     
  86.     val = CMMD_reduce_double(1.0, CMMD_combiner_add);
  87.     
  88.   } /* for */
  89.  
  90.   gettimeofday(&tp2, &tzp);
  91.   
  92.   time = ((double)(tp2.tv_sec - tp1.tv_sec)) +
  93.     ((double)(tp2.tv_usec - tp1.tv_usec)) / 1.0E+6;
  94.  
  95.   if (my_tid == ntasks) {
  96.     sprintf(fname, "reduce_timings", nbytes, ntasks);
  97.     fd = fopen(fname, "a");
  98.     fprintf(fd, "%d\t %d\t %f \n", num_iter, ntasks, time);
  99.     fclose(fd);
  100.   }
  101.   io_printf(" done.\n", my_tid, (char *)0 );
  102.   
  103.   exit(0);
  104. }
  105.  
  106.